home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / snmp / mib2c-data / mfd-access-unsorted-external-defines.m2i < prev    next >
Encoding:
Text File  |  2009-03-19  |  40.1 KB  |  1,199 lines

  1. #############################################################  -*- c -*-
  2. ## generic include for XXX. Do not use directly.
  3. ##
  4. ## $Id: mfd-access-unsorted-external-defines.m2i 11972 2005-03-02 19:35:44Z rstory $
  5. ########################################################################
  6. ##
  7. @eval $mfd_aue_wrap_param = "wrap_ctx"@
  8. @eval $mfd_aue_wrap_param_type = "${context}_interface_ctx *"@
  9. @eval $mfd_aue_wrap_param_decl = "$mfd_aue_wrap_param_type $mfd_aue_wrap_param"@
  10. ##
  11. @eval $mfd_aue_param = "${context}_reg"@
  12. @eval $mfd_aue_param_type = "${context}_registration *"@
  13. @eval $mfd_aue_param_decl = "$mfd_aue_param_type $mfd_aue_param"@
  14. @eval $mfd_aue_param_cmt = "$mfd_aue_param Pointer to a $mfd_aue_param_type"
  15. ##
  16. @if $m2c_mark_boundary == 1@
  17. /** START code generated by $RCSfile$ $Revision: 11972 $ */
  18. @end@
  19. ##//####################################################################
  20. ##//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  21. ##//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  22. @if $m2c_processing_type eq 'h'@
  23. ##
  24. @if $m2c_include_examples == 1@
  25. $example_start
  26. /* *********************************************************************
  27.  * Since we have no idea how you really access your data, we'll go with
  28.  * a worst case example: a flat text file.
  29.  @   if $m2c_data_transient != 2@
  30.  @      print Example code is for fully transient data. Either turn off@
  31.  @      print m2c_include_examples or set m2c_data_transient to 2.@
  32.  @      exit@
  33.  @   end@
  34.  */
  35. #define MAX_LINE_SIZE 256
  36. $example_end
  37.  
  38. @end@
  39. /**
  40.  * loop context
  41.  *
  42.  * TODO:
  43.  * define loop context structure
  44.  *
  45.  *  Since the actual loop is in the MFD handler, a loop contex parameter
  46.  *  is provided to help you keep track of where you are in between calls
  47.  *  to functions that you wrote and the master MFD handler calls. The
  48.  *  structure of this context is user defineable, and is defined in the
  49.  *  file ${table}_data_access.h.
  50.  *
  51.  *  E.G., if your data is stored in a linked list, the obvious thing you
  52.  *  want to know from one function call to the next is your current
  53.  *  position in the linked list.  Thus the easiest context to use is a
  54.  *  pointer within the linked list.  For an array, the current index to
  55.  *  that array would be easiest.
  56.  *
  57.  *  The funtion calls are actually passed a reference to the loop
  58.  *  context, to allow the loop context to be allocated memory. Here are
  59.  *  some simple examples definitions for various data formats. These
  60.  *  definitions are used in examples later on.
  61.  *
  62.  */
  63. typedef struct ${context}_loop_context_s {
  64.     /*
  65.      * temporary context used during iteration
  66.      */
  67.     ${context}_rowreq_ctx *rowreq_ctx;
  68. @if $m2c_include_examples == 1@
  69.     
  70.     /*
  71.      * this example code is based on a data source that is a
  72.      * text file to be read and parsed.
  73.      */
  74.     FILE *filep;
  75.     char line[MAX_LINE_SIZE];
  76. @end@
  77. } ${context}_loop_context;
  78.  
  79. /*
  80.  * define a reference to the loop context
  81.  *
  82.  * NOTE: DO NOT ADD ITEMS TO THIS STRUCTURE!
  83.  */
  84. typedef struct ${context}_ref_loop_ctx_s {
  85.     ${context}_loop_context *loop_ctx;
  86. } ${context}_ref_loop_ctx;
  87.  
  88. int ${context}_loop_get_first( $mfd_aue_param_decl, ${context}_ref_loop_ctx *loop_ctx_ref,
  89.                     ${context}_ref_rowreq_ctx *rowreq_ctx_ref);
  90. int ${context}_loop_get_next( $mfd_aue_param_decl, ${context}_ref_loop_ctx *loop_ctx_ref,
  91.                         ${context}_ref_rowreq_ctx *rowreq_ctx_ref);
  92. int ${context}_loop_get_data( $mfd_aue_param_decl, ${context}_ref_loop_ctx *loop_ctx_ref,
  93.                         ${context}_ref_rowreq_ctx *rowreq_ctx_ref);
  94. int ${context}_loop_save_position($mfd_aue_param_decl,
  95.                        ${context}_ref_loop_ctx *loop_ctx_ref,
  96.                        ${context}_ref_loop_ctx *save_loop_ctx_ref, int reuse);
  97. int ${context}_loop_cleanup_context( $mfd_aue_param_decl, ${context}_ref_loop_ctx *ref);
  98.  
  99. ##
  100. @end@ // m2c_processing_type eq 'h'
  101. ########################################################################
  102. ##//####################################################################
  103. ##//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  104. ##//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  105. @if $m2c_processing_type eq 'i'@
  106. /**
  107.  * @internal
  108.  * wrapper around clean up a loop reference
  109.  */
  110. static int
  111. _${context}_loop_cleanup_context( $mfd_aue_wrap_param_decl,
  112.                             ${context}_ref_loop_ctx *ref)
  113. {
  114.    DEBUGMSGTL(("internal:${context}:_${context}_loop_cleanup_context","called\n"));
  115.  
  116.    return ${context}_loop_cleanup_context($mfd_aue_wrap_param->user_ctx, ref);
  117. } /* _${context}_loop_cleanup_context */
  118.  
  119. /**
  120.  * @internal
  121.  * wrapper around save position
  122.  */
  123. static int
  124. _${context}_loop_save_position( $mfd_aue_wrap_param_decl, ${context}_ref_loop_ctx *ref,
  125.                          ${context}_ref_loop_ctx *ref_copy, int reuse)
  126. {
  127.    DEBUGMSGTL(("internal:${context}:_${context}_loop_save_position","called\n"));
  128.  
  129.    return ${context}_loop_save_position($mfd_aue_wrap_param->user_ctx, ref,
  130.                                  ref_copy, reuse);
  131. } /* _${context}_loop_save_position */
  132.  
  133. /**
  134.  * @internal
  135.  * wrapper around user get_first to setup the index oid
  136.  */
  137. static int
  138. _${context}_loop_get_first_wrapper($mfd_aue_wrap_param_decl,
  139.                            ${context}_ref_loop_ctx * loop_ctx_ref,
  140.                            ${context}_ref_rowreq_ctx * rowreq_ctx_ref)
  141. {
  142.     int rc;
  143.     DEBUGMSGTL(("internal:${context}:_${context}_loop_get_first_wrapper","called\n"));
  144.  
  145.     rc = ${context}_loop_get_first($mfd_aue_wrap_param->user_ctx, loop_ctx_ref,
  146.                                  rowreq_ctx_ref);
  147.     /*
  148.      * convert index to OID
  149.      */
  150.     if(SNMPERR_SUCCESS == rc ) {
  151.         netsnmp_assert((NULL != rowreq_ctx_ref) &&
  152.                        (rowreq_ctx_ref->rowreq_ctx->oid_idx.oids == rowreq_ctx_ref->rowreq_ctx->oid_tmp));
  153.         rowreq_ctx_ref->rowreq_ctx->oid_idx.len = sizeof(rowreq_ctx_ref->rowreq_ctx->oid_tmp);
  154.         rc = ${context}_index_to_oid(&rowreq_ctx_ref->rowreq_ctx->oid_idx,
  155.                                    &rowreq_ctx_ref->rowreq_ctx->tbl_idx);
  156.         netsnmp_assert(rowreq_ctx_ref->rowreq_ctx->oid_idx.len !=
  157.                        sizeof(rowreq_ctx_ref->rowreq_ctx->oid_tmp));
  158.     }
  159.  
  160.     return rc;
  161. } /* _${context}_loop_get_first_wrapper */
  162.  
  163. /**
  164.  * @internal
  165.  * wrapper around user get_next to setup the index oid
  166.  */
  167. static int
  168. _${context}_loop_get_next_wrapper($mfd_aue_wrap_param_decl,
  169.                           ${context}_ref_loop_ctx * loop_ctx_ref,
  170.                           ${context}_ref_rowreq_ctx * rowreq_ctx_ref)
  171. {
  172.     int rc;
  173.     DEBUGMSGTL(("internal:${context}:_${context}_loop_get_next_wrapper","called\n"));
  174.  
  175.     rc = ${context}_loop_get_next($mfd_aue_wrap_param->user_ctx, loop_ctx_ref,
  176.                                 rowreq_ctx_ref);
  177.     /*
  178.      * convert index to OID
  179.      */
  180.     if(SNMPERR_SUCCESS == rc ) {
  181.         netsnmp_assert((NULL != rowreq_ctx_ref) &&
  182.                        (rowreq_ctx_ref->rowreq_ctx->oid_idx.oids == rowreq_ctx_ref->rowreq_ctx->oid_tmp));
  183.         rowreq_ctx_ref->rowreq_ctx->oid_idx.len = sizeof(rowreq_ctx_ref->rowreq_ctx->oid_tmp);
  184.         rc = ${context}_index_to_oid(&rowreq_ctx_ref->rowreq_ctx->oid_idx,
  185.                                    &rowreq_ctx_ref->rowreq_ctx->tbl_idx);
  186.         netsnmp_assert(rowreq_ctx_ref->rowreq_ctx->oid_idx.len !=
  187.                        sizeof(rowreq_ctx_ref->rowreq_ctx->oid_tmp));
  188.     }
  189.  
  190.     return rc;
  191. } /* _${context}_loop_get_next_wrapper */
  192.  
  193. @if $m2c_data_transient != 0@ # 
  194. /**
  195.  * @internal
  196.  * get data wrapper to allocate context for the user
  197.  */
  198. static int
  199. _${context}_loop_get_data_wrapper($mfd_aue_wrap_param_decl,
  200.                            ${context}_ref_loop_ctx * loop_ctx_ref,
  201.                            ${context}_ref_rowreq_ctx * rowreq_ctx_ref)
  202. {
  203. //    ${context}_rowreq_ctx *orig_ctx = rowreq_ctx_ref->rowreq_ctx;
  204.  
  205.     DEBUGMSGTL(("internal:${context}:_${context}_loop_get_data_wrapper","called\n"));
  206.  
  207.     return ${context}_loop_get_data($mfd_aue_wrap_param->user_ctx, loop_ctx_ref, rowreq_ctx_ref);
  208. } /* _${context}_loop_get_data_wrapper */
  209.  
  210. @end@ // transient != 0
  211. /**
  212.  * @internal
  213.  * initialize the iterator container with functions or wrappers
  214.  */
  215. void
  216. _${context}_container_init(${context}_interface_ctx *if_ctx)
  217. {
  218.     DEBUGMSGTL(("internal:${context}:_${context}_container_init","called\n"));
  219.     
  220.     if_ctx->container = netsnmp_container_iterator_get(/** registration */
  221.         if_ctx,
  222.         /** compare */
  223.         NULL,
  224.         /** get_first */
  225.         (Netsnmp_Iterator_Loop_Key*)_${context}_loop_get_first_wrapper,
  226.         /** get_next */
  227.         (Netsnmp_Iterator_Loop_Key*)_${context}_loop_get_next_wrapper,
  228.         /** get_data */
  229. @if $m2c_data_transient != 0@ # 
  230.         (Netsnmp_Iterator_Loop_Data*)_${context}_loop_get_data_wrapper,
  231. @else@
  232.         NULL,
  233. @end@
  234.         /** save_pos */
  235.         (Netsnmp_Iterator_Ctx_Dup*)_${context}_loop_save_position,
  236.         /** init_context */
  237.         (Netsnmp_Iterator_Ctx*)NULL,
  238.         /** cleanup_context */
  239.         (Netsnmp_Iterator_Ctx*)_${context}_loop_cleanup_context,
  240.         /** free_user_ctx */
  241.         NULL,
  242.         /** sorted */
  243.         0);
  244. } /* _${context}_container_init */
  245.  
  246. ##
  247. @end@ // m2c_processing_type eq 'i'
  248. ########################################################################
  249. ##//####################################################################
  250. ##//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  251. ##//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  252. @if $m2c_processing_type eq 'c'@
  253. /**
  254.  * unsorted-external overview
  255.  *
  256.  * The unsorted external data access code works by calling a few simple
  257.  * functions to get the index value for each row. Once the agent determines
  258.  * which row is needed to process an incoming request, another function
  259.  * is called to retrieve the data for that row.
  260.  *
  261.  * A simplified version of the pseudo-code looks like this:
  262.  *
  263.  *    ${context}_loop_get_first(loop,data)
  264.  *    while( no_error ) {
  265.  *       if( best_match(data, key)
  266.  *          ${context}_loop_save_position(loop,pos);
  267.  *       ${context}_loop_get_next(loop,data)
  268.  *    }
  269.  *    ${context}_loop_get_data(pos,data)
  270.  *    ${context}_loop_cleanup_context(loop)
  271.  */
  272.  
  273. /***********************************************************************
  274.  *
  275.  * ITERATION
  276.  *
  277.  ***********************************************************************/
  278.  
  279. /**
  280.  * get the first data index
  281.  *
  282.  * Summary
  283.  * -------
  284.  *  This function is called to initialize the iterator loop context for a
  285.  *  new iteration loop and return the index(es) for the first
  286.  *  ${context}_data in the data set.
  287.  *
  288.  *  Note that during the loop, the only important thing is the indexes.
  289.  *  If access to your data is cheap/fast (e.g. you have a pointer to a
  290.  *  structure in memory), it would make sense to update the data here.
  291.  *  If, however, the accessing the data invovles more work (e.g. parsing
  292.  *  some other existing data, or peforming calculations to derive the data),
  293.  *  then you should limit yourself to setting the indexes. Extracting the
  294.  *  can be put off until the desired row is found. See the notes on
  295.  *  ${context}_loop_get_data().
  296.  *
  297.  *  Note that this function does not correspond to a SNMP GET pdu, and
  298.  *  you should return data items in whatever order they are already in.
  299.  *  (In fact, if your data is already ordered in the same order as the
  300.  *  SNMP indexes, you shouldn't be using the unsorted-access code).
  301.  *
  302.  *  This function should update the table index (rowreq_ctx_ref->rowreq_ctx->tbl_idx)
  303.  *  values for the raw data (rowreq_ctx_ref->rowreq_ctx->data).
  304.  *
  305.  * More Details
  306.  * ------------
  307.  *  If there is currently no data available, return MFD_END_OF_DATA.
  308.  *  Otherwise, you should set rowreq_ctx_ref->rowreq_ctx and its indexes.
  309.  *
  310.  *  rowreq_ctx_ref->rowreq_ctx will be NULL. You should allocate a new context
  311.  *  for this loop. [Alternatively, you could allocate one in
  312.  *  ${context}_loop_init_context, save it in your
  313.  *  ${context}_ref_loop_ctx, and use it here.]
  314.  *
  315.  *  Once you have your context pointer, you should set the index (or indexes)
  316.  *  in rowreq_ctx_ref->rowreq_ctx->tbl_idx to the appropriate value for this row. [If you
  317.  *  use your loop_ctx_ref cleverly, you might be able to put this work in
  318.  *  ${context}_loop_get_next, and simply call that function.]
  319.  *
  320.  * @param $mfd_aue_param_cmt
  321.  * @param loop_ctx_ref  Pointer to your loop reference.
  322.  * @param rowreq_ctx_ref  Pointer to a context reference.
  323.  *
  324.  * @retval MFD_SUCCESS     : success.
  325.  * @retval MFD_END_OF_DATA : no data available
  326.  * @retval MFD_ERROR       : error.
  327.  */
  328. int
  329. ${context}_loop_get_first( $mfd_aue_param_decl, ${context}_ref_loop_ctx *loop_ctx_ref,
  330.                     ${context}_ref_rowreq_ctx *rowreq_ctx_ref)
  331. {
  332.     DEBUGMSGTL(("verbose:${context}:${context}_loop_get_first","called\n"));
  333.  
  334.     netsnmp_assert(rowreq_ctx_ref);
  335.     netsnmp_assert(loop_ctx_ref);
  336.     
  337.     /*
  338.      * allocate memory for new structure
  339.      */
  340.     loop_ctx_ref->loop_ctx = SNMP_MALLOC_TYPEDEF(${context}_loop_context);
  341.     if(NULL == loop_ctx_ref->loop_ctx)
  342.         return MFD_ERROR;
  343.  
  344.     /*
  345.      * allocate a temporary context to use during iteration
  346.      */
  347. @   eval $m2c_tmp = ""@
  348. @   if ($m2c_data_allocate == 1) || ($m2c_data_init == 1)@
  349. @      eval $m2c_tmp = "NULL"@
  350. @      if ($m2c_data_allocate == 1) && ($m2c_data_init == 1)@
  351. @         eval $m2c_tmp = "$m2c_tmp, NULL"@
  352. @      @end@
  353. @   end@
  354.     loop_ctx_ref->loop_ctx->rowreq_ctx = ${context}_allocate_rowreq_ctx($m2c_tmp);
  355.     if(NULL == loop_ctx_ref->loop_ctx->rowreq_ctx) {
  356.         SNMP_FREE(loop_ctx_ref->loop_ctx);
  357.         return MFD_RESOURCE_UNAVAILABLE;
  358.     }
  359.  
  360.     /*
  361.      * TODO:
  362.      * set up loop context
  363.      */
  364. @if $m2c_include_examples == 1@
  365. $example_start
  366.     /*
  367.      * open our data file.
  368.      */
  369.     loop_ctx_ref->loop_ctx->filep = fopen("/etc/dummy.conf", "r");
  370.     if(NULL ==  loop_ctx_ref->loop_ctx->filep) {
  371.         return MFD_RESOURCE_UNAVAILABLE;
  372.     }
  373.  
  374. $example_end
  375. @end@
  376.  
  377. @ifconf ${table}_update_idx.m2i@
  378. @   include ${table}_update_idx.m2i@
  379. @else@
  380. @   if $m2c_include_examples == 1@
  381. $example_start
  382.     /*
  383.      * in this example, after opening the file, get next does the same thing
  384.      * as get first, we let's just call get next...
  385.      */
  386.     return ${context}_loop_get_next($mfd_aue_param, loop_ctx_ref, rowreq_ctx_ref);
  387. $example_end
  388. @   else@
  389.     /*
  390.      * we just need the index for now. Reuse the one in the loop context's
  391.      * temporary row request context. (rowreq_ctx_ref->rowreq_ctx->tbl_idx)
  392.      */
  393.     rowreq_ctx_ref->rowreq_ctx = loop_ctx_ref->loop_ctx->rowreq_ctx;
  394.  
  395.     /*
  396.      * TODO:
  397.      * set local vars for index from loop_ctx_ref->loop_ctx
  398.      *  this can be done in one of two ways:
  399.      */
  400.     
  401.     /*
  402.      * 1) individually
  403.      */
  404. @   foreach $node index@
  405. @      include m2c_setup_node.m2i@
  406.         /*
  407.          * TODO:
  408.          * set rowreq_ctx_ref->rowreq_ctx->tbl_idx->$node
  409. @      if $m2c_node_needlength == 1@
  410.          *     and rowreq_ctx_ref->tbl_idx->${node}_len
  411. @      end@
  412.          */
  413. @   end@ #foreach
  414.  
  415.     /*
  416.      * OR
  417.      */
  418.  
  419.         /*
  420.          * 2) by calling ${context}_indexes_set()
  421.          * ${context}_indexes_set(rowreq_ctx_ref->tbl_idx,
  422. @   foreach $node index@
  423. @      include m2c_setup_node.m2i@
  424. @        if $m2c_node_needlength == 1@
  425.     *       ${node}_ptr, ${node}_len
  426. @        else@
  427.     *       $node
  428. @        end@
  429. @   end@ # foreach index
  430.     *      );
  431.     */
  432. @   end@ # example
  433. @end@ #ifconf
  434.  
  435.     return MFD_SUCCESS;
  436. } /* ${context}_loop_get_first */
  437.  
  438. /**
  439.  * get the next data index
  440.  *
  441.  * Summary
  442.  * -------
  443.  *  This function returns the next data item in the data set. The same
  444.  *  caveat applies here as did above. The indexes are the important parts
  445.  *  during loop processing.
  446.  *
  447.  *  Note that this function does not correspond to a SNMP GET-NEXT pdu, and
  448.  *  you should return data items in whatever order they are already in.
  449.  *  (In fact, if your data is already ordered in the same order as the
  450.  *  SNMP indexes, you shouldn't be using the unsorted-access code).
  451.  *
  452.  * More Details
  453.  * ------------
  454.  * rowreq_ctx_ref->rowreq_ctx will have been set in ${context}_loop_get_first.
  455.  *
  456.  * If there is currently no data available, return MFD_END_OF_DATA.
  457.  * Otherwise, you should set the indexes in rowreq_ctx_ref->rowreq_ctx->tbl_idx.
  458.  *
  459.  * You should set the index (or indexes) in rowreq_ctx_ref->rowreq_ctx->tbl_idx to the
  460.  * appropriate value for this row.
  461.  *
  462.  * @param $mfd_aue_param_cmt
  463.  * @param loop_ctx_ref  Pointer to your loop reference.
  464.  * @param rowreq_ctx_ref  Pointer to a context reference.
  465.  *
  466.  * @retval MFD_SUCCESS     : success.
  467.  * @retval MFD_END_OF_DATA : no more data available
  468.  * @retval MFD_ERROR       : error.
  469.  */
  470. int
  471. ${context}_loop_get_next( $mfd_aue_param_decl, ${context}_ref_loop_ctx *loop_ctx_ref,
  472.                         ${context}_ref_rowreq_ctx *rowreq_ctx_ref)
  473. {
  474.     DEBUGMSGTL(("verbose:${context}:${context}_loop_get_next","called\n"));
  475.  
  476.     netsnmp_assert(loop_ctx_ref && loop_ctx_ref->loop_ctx);
  477.     netsnmp_assert(rowreq_ctx_ref);
  478.  
  479.     /*
  480.      * we just need the index for now. Reuse the one in the loop context's
  481.      * temporary row request context. (rowreq_ctx_ref->rowreq_ctx->tbl_idx)
  482.      */
  483.     rowreq_ctx_ref->rowreq_ctx = loop_ctx_ref->loop_ctx->rowreq_ctx;
  484.    
  485. @   if $m2c_include_examples == 1@
  486. $example_start
  487.     /*
  488.      * get a line (skip blank lines)
  489.      */
  490.     do {
  491.         if (!fgets(loop_ctx_ref->loop_ctx->line, sizeof(loop_ctx_ref->loop_ctx->line),
  492.                    loop_ctx_ref->loop_ctx->filep)) {
  493.             /* we're done */
  494.             fclose(loop_ctx_ref->loop_ctx->filep);
  495.             loop_ctx_ref->loop_ctx->filep = NULL;
  496.         }
  497.     } while (loop_ctx_ref->loop_ctx->filep && (loop_ctx_ref->loop_ctx->line[0] == '\n'));
  498.  
  499.     /*
  500.      * check for end of data
  501.      */
  502.     if(NULL == loop_ctx_ref->loop_ctx->filep)
  503.         return MFD_END_OF_DATA;
  504.  
  505.     /*
  506.      * TODO:
  507.      * set local vars for index from loop_ctx_ref->loop_ctx
  508.      *  this can be done in one of two ways:
  509.      */
  510.     
  511.     /*
  512.      * 1) individually
  513.      */
  514. @   foreach $node index@
  515. @      include m2c_setup_node.m2i@
  516.         /*
  517.          * TODO:
  518.          * set rowreq_ctx_ref->rowreq_ctx->tbl_idx->$node
  519. @      if $m2c_node_needlength == 1@
  520.          *     and rowreq_ctx_ref->tbl_idx->${node}_len
  521. @      end@
  522.          */
  523. @   end@ #foreach
  524.  
  525.     /*
  526.      * OR
  527.      */
  528.  
  529.         /*
  530.          * 2) by calling ${context}_indexes_set()
  531.          * ${context}_indexes_set(rowreq_ctx_ref->tbl_idx,
  532. @   foreach $node index@
  533. @      include m2c_setup_node.m2i@
  534. @        if $m2c_node_needlength == 1@
  535.     *       ${node}_ptr, ${node}_len
  536. @        else@
  537.     *       $node
  538. @        end@
  539. @   end@ # foreach index
  540.     *      );
  541.     */
  542. $example_end
  543. @    end@ # example
  544.  
  545.     return MFD_SUCCESS;
  546. } /* ${context}_loop_get_next */
  547.  
  548. /**
  549.  * duplicate the current loop reference
  550.  *
  551.  * Summary
  552.  *  -------
  553.  *  During loop iteration, the iterator keeps track of the row that
  554.  *  is the current best match. This function is called when the
  555.  *  current row is a better match than any previous row.
  556.  *
  557.  *  You should save any information you need to be able to locate this row
  558.  *  again from the current loop context to a new loop context.
  559.  *
  560.  *  At the end of the loop, when the best match has been found, the saved
  561.  *  loop context will be used to get the data for the row by calling
  562.  *  ${context}_loop_get_data().
  563. @if $m2c_data_transient != 0@ # persistent
  564.  *
  565.  *  Since your data is transient, you need to make a copy of it before
  566.  *  the iterator moves on to the next row.
  567. @end@
  568.  *
  569. @if $m2c_data_transient != 0@ # persistent
  570.  * More Details
  571.  * ------------
  572. @   if $m2c_data_transient == 1@ # short term
  573.  *  Since your data is semi-TRANSIENT data, you could just keep a pointer
  574.  *  to the data in the loop reference. The data should then be copied in
  575.  *  ${context}_loop_get_data().
  576. @   else@ # $m2c_data_transient == 2@ # copy immediately
  577.  *  One idea would be to copy it space allocated in the loop reference
  578.  *  structure. Another would be to simply have a pointer in the loop
  579.  *  reference structure, and allocate memory here.
  580.  *
  581. @   end@
  582. @end@
  583.  * @param $mfd_aue_param_cmt
  584.  * @param loop_ctx_ref  Reference to current loop context.
  585.  * @param save_loop_ctx_ref Reference to a loop context for saving the current
  586.  *                  position. If reuse is not set or
  587.  *                  save_loop_ctx_ref->loop_ctx is NULL, allocate
  588.  *                  a new one. If reuse is set, you may reuse  the existing
  589.  *                  loop_ctx.
  590.  * @param reuse     Indicates if an existing save_loop_ctx_ref->loop_ctx
  591.  *                  may be reused.
  592.  *
  593.  * @retval MFD_SUCCESS : success.
  594.  * @retval MFD_ERROR   : error.
  595.  */
  596. int
  597. ${context}_loop_save_position($mfd_aue_param_decl,
  598.                        ${context}_ref_loop_ctx *loop_ctx_ref,
  599.                        ${context}_ref_loop_ctx *save_loop_ctx_ref,
  600.                        int reuse)
  601. {
  602.     DEBUGMSGTL(("verbose:${context}:${context}_loop_save_position","called\n"));
  603.  
  604.     netsnmp_assert(loop_ctx_ref && save_loop_ctx_ref);
  605.  
  606.     /*
  607.      * TODO:
  608.      * 1) allocate new loop context, unless you can reuse a previous pointer.
  609.      * 2) save information for the position of loop_ctx_ref in save_loop_ctx_ref.
  610.      */
  611.     if((0 == reuse) || (NULL == save_loop_ctx_ref->loop_ctx))
  612.         save_loop_ctx_ref->loop_ctx = SNMP_MALLOC_TYPEDEF(${context}_loop_context);
  613.     if(NULL == save_loop_ctx_ref->loop_ctx) {
  614.         snmp_log(LOG_ERR, "could not allocate memory\n");
  615.         return MFD_ERROR;
  616.     }
  617.  
  618.     /*
  619.      * if you can reuse a previously saved contex, just swap
  620.      * it out with the loop iterator
  621.      */
  622.     if(reuse && save_loop_ctx_ref->loop_ctx->rowreq_ctx) {
  623.         ${context}_rowreq_ctx * tmp_rowreq_ctx = save_loop_ctx_ref->loop_ctx->rowreq_ctx;
  624.         save_loop_ctx_ref->loop_ctx->rowreq_ctx = loop_ctx_ref->loop_ctx->rowreq_ctx;
  625.         loop_ctx_ref->loop_ctx->rowreq_ctx = tmp_rowreq_ctx;
  626.     }
  627.     else {
  628.         /*
  629.          * take the current pointer
  630.          */
  631.         save_loop_ctx_ref->loop_ctx->rowreq_ctx = loop_ctx_ref->loop_ctx->rowreq_ctx;
  632.         
  633.         /*
  634.          * allocate a new context to replace the one you just took.
  635.          */
  636. @   eval $m2c_tmp = ""@
  637. @   if ($m2c_data_allocate == 1) || ($m2c_data_init == 1)@
  638. @      eval $m2c_tmp = "NULL"@
  639. @      if ($m2c_data_allocate == 1) && ($m2c_data_init == 1)@
  640. @         eval $m2c_tmp = "$m2c_tmp, NULL"@
  641. @      @end@
  642. @   end@
  643.         loop_ctx_ref->loop_ctx->rowreq_ctx = ${context}_allocate_rowreq_ctx($m2c_tmp);
  644.         if(NULL == loop_ctx_ref->loop_ctx->rowreq_ctx) {
  645.             SNMP_FREE(loop_ctx_ref->loop_ctx);
  646.             return MFD_ERROR;
  647.         }
  648.     }
  649.  
  650. @if $m2c_data_transient == 0@ # persistent
  651.     /** non-TRANSIENT data: no need to copy */
  652. @elsif $m2c_data_transient == 1@ # short term
  653.     /** semi-TRANSIENT data: will copy data when index found */
  654.     /** only need to copy pertinent data from loop context */
  655. @elsif $m2c_data_transient == 2@ # copy immediately
  656.     /*
  657.      * TRANSIENT data: copy all the data.
  658.      */
  659. @end@
  660. @if $m2c_include_examples == 1@
  661. $example_start
  662. @  if $m2c_data_transient == 1@ # short term
  663.     /** save line to do that */
  664.     memcpy(save_loop_ctx_ref->loop_ctx->line, loop_ctx_ref->loop_ctx->line,
  665.            sizeof(loop_ctx_ref->loop_ctx->line));
  666. @  elsif $m2c_data_transient == 2@ # copy immediately
  667. @    foreach $node nonindex@
  668. @      include m2c_setup_node.m2i@
  669.     /*
  670.      * TODO:
  671.      * set rowreq_ctx_ref->${m2c_data_item}$node
  672.      *     from the loop context
  673.      */
  674. @    end@
  675. @  end@
  676. $example_end
  677. @end@ # example
  678.     
  679.     return MFD_SUCCESS;
  680. } /* ${context}_loop_save_position */
  681.  
  682. @if $m2c_data_transient != 0@ # semi-transient
  683. /**
  684.  * set ${context}_data from a data context
  685.  *
  686.  * Summary
  687.  * -------
  688.  *  At the end of the loop, when the best match has been found, the saved
  689.  *  loop context will be used to get the data for the row by calling
  690.  *  ${context}_loop_get_data().
  691.  *
  692.  *  You should return a fully populated row request context in
  693.  *  rowreq_ctx_ref->rowreq_ctx.
  694.  *
  695.  * More Details
  696.  * ------------
  697.  * @param $mfd_aue_param_cmt
  698.  * @param loop_ctx_ref pointer to your loop reference.
  699.  * @param rowreq_ctx_ref pointer to a context reference.
  700.  */
  701. int
  702. ${context}_loop_get_data( $mfd_aue_param_decl, ${context}_ref_loop_ctx *loop_ctx_ref,
  703.                            ${context}_ref_rowreq_ctx *rowreq_ctx_ref)
  704. {
  705.     DEBUGMSGTL(("verbose:${context}:${context}_loop_get_data","called\n"));
  706.  
  707.     netsnmp_assert((NULL != loop_ctx_ref) && (NULL != loop_ctx_ref->loop_ctx));
  708.     netsnmp_assert(NULL != rowreq_ctx_ref);
  709.     netsnmp_assert(NULL != rowreq_ctx_ref->rowreq_ctx);
  710.  
  711.     /*
  712.      * take temporary row request context from loop context
  713.      */
  714.     rowreq_ctx_ref->rowreq_ctx = loop_ctx_ref->loop_ctx->rowreq_ctx;
  715.     loop_ctx_ref->loop_ctx->rowreq_ctx = NULL;
  716.     
  717.     /*
  718.      * copy data to the data context (rowreq_ctx_ref->${m2c_data_item})
  719. @   if $m2c_include_examples == 1@
  720.      * in loop_save_position, we saved line to do that
  721. @   end@
  722.      */
  723. @   foreach $node nonindex@
  724. @      include m2c_setup_node.m2i@
  725.     /*
  726.      * $m2c_node_summary
  727.      */
  728. @   eval $m2c_ctx_lh = "rowreq_ctx_ref->$m2c_ctx_rh"@
  729. @   eval $m2c_ctx_lhs = "rowreq_ctx_ref->$m2c_ctx_rhs"@
  730. @   eval $m2c_ctx_rh = "loop_ctx_ref->loop_ctx->$node"@
  731. @   eval $m2c_ctx_rhs = "loop_ctx_ref->loop_ctx->${node}_len"@
  732. @   include generic-value-map.m2i@
  733.     
  734. @   end@
  735.  
  736.    return MFD_SUCCESS;
  737. } /* ${context}_loop_get_data */
  738.  
  739. @end@ // if $m2c_data_transient != 0
  740.  
  741. /**
  742.  * clean up a loop reference
  743.  *
  744.  * Summary
  745.  * -------
  746.  *  This function will be called once the loop iteration has completed
  747.  *  to release any memory or resources allocated for the loop context.
  748.  *
  749.  * More Details
  750.  * ------------
  751.  * @param $mfd_aue_param_cmt
  752.  * @param loop_ctx_ref  Pointer to your loop reference.
  753.  *
  754.  * @retval MFD_SUCCESS : success.
  755.  * @retval MFD_ERROR   : error.
  756.  */
  757. int
  758. ${context}_loop_cleanup_context( $mfd_aue_param_decl, ${context}_ref_loop_ctx *loop_ctx_ref)
  759. {
  760.     DEBUGMSGTL(("verbose:${context}:${context}_loop_cleanup_context","called\n"));
  761.     
  762.     netsnmp_assert(loop_ctx_ref);
  763.     
  764.     if(!loop_ctx_ref->loop_ctx)
  765.         return MFD_ERROR;
  766.  
  767.     /*
  768.      * release the row request context, if it wasn't taken
  769.      */
  770.     if(loop_ctx_ref->loop_ctx->rowreq_ctx)
  771.         ${context}_release_rowreq_ctx(loop_ctx_ref->loop_ctx->rowreq_ctx);
  772.  
  773.     /*
  774.      * TODO:
  775.      * release resources
  776.      */
  777. @if $m2c_include_examples == 1@
  778. $example_start
  779.     /*
  780.      * close file
  781.      */
  782.     if(loop_ctx_ref->loop_ctx->filep)
  783.         fclose(loop_ctx_ref->loop_ctx->filep);
  784. $example_end
  785.     
  786. @end@
  787.     /*
  788.      * free loop context
  789.      */
  790.     free(loop_ctx_ref->loop_ctx);
  791.     
  792.     return MFD_SUCCESS;
  793. } /* ${context}_loop_cleanup_context */
  794.  
  795. @end@ // m2c_processing_type eq 'c'
  796. ########################################################################
  797. ##//####################################################################
  798. ##//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  799. ##//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  800. @if $m2c_processing_type eq 'r'@
  801. ##
  802.   unsorted-external summary
  803.   -------------------------
  804.     The unsorted-external data access code is for cases when you data is
  805.     kept UNSORTED and EXTERNAL to the agent/sub-agent.
  806.  
  807.     This code was generated based on the following assumptions or settings:
  808.  
  809.     1) The raw data for this table is UNSORTED.
  810.     @if $mfd_readme_verbose != 0@
  811.  
  812.        UNSORTED data is data that is not kept in the same order as the way
  813.        SNMP expects the index(es) for the table to be kept. [It could very
  814.        well be sorted in some other order, but for the purpose of SNMP, the
  815.        order is incorrect.]  If you're not sure if your data is sorted
  816.        in an SNMP compliant way, its likely not.
  817.  
  818.        Because the raw data is unsorted, to satisfy a particular request, the
  819.        entire data set must be examined to find the apropriate index. This
  820.        is done via a simple loop. The MFD handler will call your get_first
  821.        function and the call the get_next function repeatedly, until it
  822.        returns SNMPERR_NO_VARS.
  823.     @end@
  824.  
  825.     2) The raw data for this table is EXTERNAL.
  826.     @if $mfd_readme_verbose != 0@
  827.  
  828.        EXTERNAL data is data that is owned by some other process,
  829.        device, file or mechanism.  The agent must use some interface to
  830.        read or modify the data.  An external process may modify the data
  831.        without the agent's knowledge. For example, the Net-SNMP agent
  832.        implements the interface table (ifTable), which reports on
  833.        network interfaces. The host operating system owns this data, and
  834.        Net-SNMP must use system calls to report or manipulate the data.
  835.        Examples of external data include data stored in kernel space, in
  836.        files, in another non-memory shared process, and data stored in
  837.        devices.
  838.     @end@
  839.  
  840.     3) The raw data for this table is TRANSIENT.
  841.     @if $mfd_readme_verbose != 0@
  842.  
  843.        TRANSIENT data is data that may be overwritten by another funtion
  844.        or process. For example, many OS functions return data in a
  845.        static buffer that will be reused the next time the function is
  846.        called.  Because of this, we will assume that you will copy the
  847.        raw data retrieved from these other sources to a generated
  848.        structure for use within the Net-SNMP agent.  (Don't worry, we'll
  849.        help you)
  850.     @end@
  851.  
  852.  
  853. ##
  854. ## this should be syncronized with master version of comments in
  855. ## mfd-access-unsorted-external-body.m2i You should be able to copy
  856. ## the comments here and replace " * " with "   ".
  857. ##
  858.   The unsorted external data access code works by calling a few simple
  859.   functions to get the index value for each row. Once the agent determines
  860.   which row is needed to process an incoming request, another function
  861.   is called to retrieve the data for that row.
  862.  
  863.   A simplified version of the pseudo-code looks like this:
  864.  
  865.      ${context}_loop_init_context(loop)
  866.      ${context}_loop_get_first(loop,data)
  867.      while( no_error ) {
  868.         if( best_match(data, key)
  869.            ${context}_loop_save_position(loop,pos);
  870.         ${context}_loop_get_next(loop,data)
  871.      }
  872.      ${context}_loop_get_data(pos,data)
  873.      ${context}_loop_cleanup_context(loop)
  874. ##
  875. ## end sync
  876. ##
  877.  
  878.   We will talk about each individual step below.
  879.  
  880.  
  881. ########################################################################
  882.   Defining context for the loop
  883.   -----------------------------
  884.     TODO : typedef ${context}_loop_context
  885.     WHERE: ${table}_data_access.h
  886.  
  887.     @if $mfd_readme_verbose != 0@
  888. ##
  889. ## this should be syncronized with master version of comments in
  890. ## mfd-access-unsorted-external-body.m2i You should be able to copy
  891. ## the comments here and replace " * " with "   ".
  892. ##
  893.     Since the actual loop is in the MFD handler, a loop contex parameter
  894.     is provided to help you keep track of where you are in between calls
  895.     to functions that you wrote and the master MFD handler calls. The
  896.     structure of this context is user defineable, and is defined in the
  897.     file ${table}_data_access.h.
  898.  
  899.     E.G., if your data is stored in a linked list, the obvious thing you
  900.     want to know from one function call to the next is your current
  901.     position in the linked list.  Thus the easiest context to use is a
  902.     pointer within the linked list.  For an array, the current index to
  903.     that array would be easiest.
  904.  
  905.     The funtion calls are actually passed a reference to the loop
  906.     context, to allow the loop context to be allocated memory. Here are
  907.     some simple examples definitions for various data formats. These
  908.     definitions are used in examples later on.
  909. ##
  910. ## end sync
  911. ##
  912.  
  913.       Linked list
  914.       -----------
  915.           typedef list_node ${context}_loop_context;
  916.  
  917.       Array
  918.       -----
  919.           typedef integer ${context}_loop_context;
  920.  
  921.       File
  922.       ----
  923.           typedef struct ${context}_loop_context_s {
  924.                char *      file_name;
  925.                FILE *      f;
  926.                char        line[128];
  927.           } ${context}_loop_context;
  928.  
  929.   @end@
  930.  
  931. ########################################################################
  932.   Initialization
  933.   --------------
  934.     TODO : Initialization
  935.     FUNC : ${context}_loop_init_data
  936.     WHERE: ${table}_data_access.c
  937.  
  938.     @if $mfd_readme_verbose != 0@
  939.     The ${context}_loop_init_data function will be called during startup to
  940.     allow for any initialization needed for the data access routines.
  941.  
  942.     @end@
  943.  
  944. ########################################################################
  945.   Preparing for the loop
  946.   ----------------------
  947.     TODO : initialize loop context
  948.     FUNC : ${context}_loop_init_context
  949.     WHERE: ${table}_data_access.c
  950.  
  951.     @if $mfd_readme_verbose != 0@
  952. ##
  953. ## this should be syncronized with master version of comments in
  954. ## mfd-access-unsorted-external-body.m2i You should be able to copy
  955. ## the comments here and replace " * " with "   ".
  956. ##
  957.     This function will be called before the start of a new itertion over
  958.     the data. The loop context that is initialized here will be passed to
  959.     ${context}_loop_get_first and ${context}_loop_get_next.
  960.   
  961.     Set the loop context variable ref->loop_ctx so that the iteration
  962.     functions (get_first and get_next) can locate the apropriate data
  963.     context.
  964. ##
  965. ## end sync
  966. ##
  967.  
  968.     The primary purpose of the loop_init_context call  is to initialize
  969.     the loop context data (ref). Here are some simple examples, based on the
  970.     earlier example loop contexts.
  971.  
  972.       Linked list
  973.       -----------
  974.           ref->loop_ctx = my_table_head_ptr;
  975.  
  976.       Array
  977.       -----
  978.           /* instead of actually allocating memory, just use the pointer */
  979.           /* as an integer */
  980.           (integer)(ref->loop_ctx) = 0;
  981.  
  982.       File
  983.       ----
  984.           ref->loop_ctx = SNMP_MALLOC_TYPEDEF(${context}_loop_context);
  985.           /* error checking here */
  986.           ref->loop_ctx->file_name = (char*) reg->mfd_user_ctx;
  987.           ref->loop_ctx->f = fopen( ref->loop_ctx->file_name, "r+" );
  988.  
  989.   @end@
  990.  
  991. ########################################################################
  992.   The Loop
  993.   --------
  994.     TODO : return raw data
  995.     FUNC : ${context}_loop_get_first
  996.     WHERE: ${table}_data_access.c
  997.  
  998.     @if $mfd_readme_verbose != 0@
  999. ##
  1000. ## this should be syncronized with master version of comments in
  1001. ## mfd-access-unsorted-external-body.m2i You should be able to copy
  1002. ## the comments here and replace " * " with "   ".
  1003. ##
  1004.     This function is called to return set the index(es) for the first
  1005.     ${context}_data in the data set.
  1006.  
  1007.     Note that during the loop, the only important thing is the indexes.
  1008.     If access to your data is cheap/fast (e.g. you have a pointer to a
  1009.     structure in memory), it would make sense to update the data here.
  1010.     If, however, the accessing the data invovles more work (e.g. parsing
  1011.     some other existing data, or peforming calculations to derive the data),
  1012.     then you should limit yourslef to setting the indexes. Extracting the
  1013.     can be put off until the desired row is found See the notes on
  1014.     ${context}_loop_get_data().
  1015.  
  1016.     Note that this function does not correspond to a SNMP GET pdu, and
  1017.     you should return data items in whatever order they are already in.
  1018.     (In fact, if your data is already ordered in the same order as the
  1019.     SNMP indexes, you shouldn't be using the unsorted-access code).
  1020.   
  1021.     This function should update the table index (rowreq_ctx_ref->rowreq_ctx->tbl_idx)
  1022.     values for the raw data (rowreq_ctx_ref->rowreq_ctx->data).
  1023. ##
  1024. ## end sync
  1025. ##
  1026.  
  1027.       Linked list
  1028.       -----------
  1029.           rowreq_ctx_ref->rowreq_ctx->data = loop_ctx_ref->loop_ctx;
  1030.  
  1031.       Array
  1032.       -----
  1033.           /* assuming registration has array of pointers */
  1034.           rowreq_ctx_ref->rowreq_ctx->data = reg->mfd_user_ctx[(integer)(ref->loop_ctx)];
  1035.  
  1036.       File
  1037.       ----
  1038.           fgets(loop_ctx_ref->loop_ctx->line, sizeof(loop_ctx_ref->loop_ctx->line),
  1039.                 loop_ctx_ref->loop_ctx->f);
  1040.           rowreq_ctx_ref->rowreq_ctx->data = loop_ctx_ref->loop_ctx->line;
  1041.  
  1042.     @end@
  1043.  
  1044.     TODO : return raw data
  1045.     FUNC : ${context}_loop_get_next
  1046.     WHERE: ${table}_data_access.c
  1047.  
  1048.     @if $mfd_readme_verbose != 0@
  1049. ##
  1050. ## this should be syncronized with master version of comments in
  1051. ## mfd-access-unsorted-external-body.m2i You should be able to copy
  1052. ## the comments here and replace " * " with "   ".
  1053. ##
  1054.     This function returns the next data item in the data set. The same
  1055.     caveat applies here as did above. The indexes are the important parts
  1056.     during loop processing.
  1057.  
  1058.     Note that this function does not correspond to a SNMP GET-NEXT pdu, and
  1059.     you should return data items in whatever order they are already in.
  1060.     (In fact, if your data is already ordered in the same order as the
  1061.     SNMP indexes, you shouldn't be using the unsorted-access code).
  1062. ##
  1063. ## end sync
  1064. ##
  1065.  
  1066.       Linked list
  1067.       -----------
  1068.           loop_ctx_ref->loop_ctx = loop_ctx_ref->loop_ctx->next;
  1069.           rowreq_ctx_ref->rowreq_ctx->data = loop_ctx_ref->loop_ctx;
  1070.  
  1071.       Array
  1072.       -----
  1073.           ++((integer)(ref->loop_ctx));
  1074.           /* assuming registration has array of pointers */
  1075.           rowreq_ctx_ref->rowreq_ctx->data = reg->mfd_user_ctx[(integer)(ref->loop_ctx)];
  1076.  
  1077.       File
  1078.       ----
  1079.           fgets(loop_ctx_ref->loop_ctx->line, sizeof(loop_ctx_ref->loop_ctx->line),
  1080.                 loop_ctx_ref->loop_ctx->f);
  1081.           rowreq_ctx_ref->rowreq_ctx->data = loop_ctx_ref->loop_ctx->line;
  1082.  
  1083.     @end@
  1084.  
  1085. ########################################################################
  1086.   Updating the Index
  1087.   ------------------
  1088.     TODO : update index for the raw data
  1089.     FUNC : ${context}_indexes_set
  1090.     WHERE: ${table}_data_access.c
  1091.  
  1092.     This is a convenience function for setting the index context from
  1093.     the native C data. Where necessary, value mapping should be done.
  1094.  
  1095.     @if $mfd_readme_verbose == 1@
  1096.     This function should update the table index values (found in
  1097.     tbl_idx) for the given raw data.
  1098.  
  1099.     @end@
  1100.  
  1101. ########################################################################
  1102.   Saving a position in the loop
  1103.   -----------------------------
  1104.     TODO : Saving a position in the loop
  1105.     FUNC : ${context}_loop_save_position
  1106.     WHERE: ${table}_data_access.c
  1107.  
  1108.     @if $mfd_readme_verbose != 0@
  1109. ##
  1110. ## this should be syncronized with master version of comments in
  1111. ## mfd-access-unsorted-external-body.m2i You should be able to copy
  1112. ## the comments here and replace " * " with "   ".
  1113. ##
  1114.     During loop iteration, the iterator keeps track of the row that
  1115.     is the current best match. This function is called when the
  1116.     current row is a better match than any previous row.
  1117.   
  1118.     You should save any information you need to be able to locate this row
  1119.     again from the current loop context to a new loop context.
  1120.   
  1121.     At the end of the loop, when the best match has been found, the saved
  1122.     loop context will be used to get the data for the row by calling
  1123.     ${context}_loop_get_data().
  1124. @if $m2c_data_transient != 0@ # persistent
  1125.   
  1126.     Since your data is transient, you need to make a copy of it before
  1127.     the iterator moves on to the next row.
  1128. @end@
  1129. ##
  1130. ## end sync
  1131. ##
  1132.  
  1133.     @end@
  1134.  
  1135. ########################################################################
  1136.   Returning Data For an Index
  1137.   ---------------------------
  1138.     TODO : copy transient raw data to generated structure
  1139.     FUNC : ${context}_loop_get_data
  1140.     WHERE: ${table}_data_access.c
  1141.  
  1142.     @if $mfd_readme_verbose != 0@
  1143. ##
  1144. ## this should be syncronized with master version of comments in
  1145. ## mfd-access-unsorted-external-body.m2i You should be able to copy
  1146. ## the comments here and replace " * " with "   ".
  1147. ##
  1148.     At the end of the loop, when the best match has been found, the saved
  1149.     loop context will be used to get the data for the row by calling
  1150.     ${context}_loop_get_data().
  1151. ##
  1152. ## end sync
  1153. ##
  1154.  
  1155.     @end@
  1156.  
  1157. ########################################################################
  1158.   Cleaning up after the loop
  1159.   --------------------------
  1160.     TODO : release any allocated memory
  1161.     FUNC : ${context}_loop_cleanup_context
  1162.     WHERE: ${table}_data_access.c
  1163.  
  1164.     @if $mfd_readme_verbose != 0@
  1165. ##
  1166. ## this should be syncronized with master version of comments in
  1167. ## mfd-access-unsorted-external-body.m2i You should be able to copy
  1168. ## the comments here and replace " * " with "   ".
  1169. ##
  1170.     This function will be called once the loop iteration has completed
  1171.     to release any memory allocated for loop reference.
  1172. ##
  1173. ## end sync
  1174. ##
  1175.     The purpose of the loop_cleanup_context call is to release any memory
  1176.     allocated for the loop context data. Here are some simple examples, based
  1177.     on the earlier example loop contexts.
  1178.  
  1179.       Linked list
  1180.       -----------
  1181.           /* nothing to do */
  1182.  
  1183.       Array
  1184.       -----
  1185.           /* nothing to do */
  1186.  
  1187.       File
  1188.       ----
  1189.           free(ref->loop_ctx);
  1190.  
  1191.     @end@
  1192.  
  1193. ##
  1194. @end@ // m2c_processing_type eq 'r
  1195. ########################################################################
  1196. @if $m2c_mark_boundary == 1@
  1197. /** END code generated by $RCSfile$ $Revision: 11972 $ */
  1198. @end@
  1199.